﻿using System;
using System.Threading;
using System.Threading.Tasks;

namespace WSU.ChekaParallel.TestTask.Await
{
    static class TestAwaitExceptions
    {
        private static async void SimpleDemo()
        {
            try
            {
                await Task.Run(() =>
                             {
                                 Console.WriteLine("begin task, ......");
                                 Thread.Sleep(1000);
                                 throw new InvalidOperationException("for test");
                             });
            }
            // note: because we are using "await", so the exception we are catching the exact
            // exception thrown, NOT AggregatedException
            catch (InvalidOperationException ex)
            {
                Console.WriteLine("!!! exact exception caught: '{0}'", ex.Message);
            }
        }

        public static void TestMain()
        {
            SimpleDemo();
            Helper.Pause();
        }
    }
}
